{*
  Object Pascal simple object manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
  @version 2008/05/16 Added ObjectHasProperty function
}
unit ObjectRoutines;

interface

uses
  SysUtils,
  Classes,
  Contnrs;

function ClearObjectList( aObjectList: TObjectList ): Boolean;
function ClearStringList( aStringList: TStringList ): Boolean;
function ObjectHasProperty(const aObject: TObject; const aProperty: AnsiString): PPropInfo;

implementation

function ClearObjectList( aObjectList: TObjectList ): Boolean;
var
  intA: Integer;
begin

  Result := True;

  try
    if Assigned(aObjectList) then
    begin
      for intA := 0 to aObjectList.Count -1 do
      begin
        if Assigned( aObjectList.Items[intA] ) then
        begin
          aObjectList.Items[intA].Free;
          aObjectList.Items[intA] := nil;
        end;//if
      end;//for
    end;//if
  except
    Result := False;
  end;//try

end;

function ClearStringList( aStringList: TStringList ): Boolean;
var
  intA: Integer;
begin

  Result := True;

  try
    for intA := 0 to aStringList.Count -1 do
    begin
      if Assigned( aStringList.Objects[intA] ) then
      begin
        aStringList.Objects[intA].Free;
        aStringList.Objects[intA] := nil;
      end;//if
    end;
  except
    Result := False;
  end;//try
end;

{*
  Determines if an object has got specific property specified as string
  To set up a property on an object, use: SetOrdProp(Label1, p, clRed)
  @return Returns True if object supports given property, False otherwise
*}

function ObjectHasProperty(const aObject: TObject; const aProperty: AnsiString): PPropInfo;
begin
  Result := GetPropInfo(aObject.ClassInfo, aProperty);
end;

end.
